package com.glory.brepda.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.activity.mfg.EquipmentTransferCompleteActivity;
import com.glory.brepda.activity.mfg.eqpStateCompleteActivity;
import com.glory.brepda.entity.EquCallOutStateEntity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;


import java.util.List;

public class GroupEquTransferStateListAdapter extends BaseQuickAdapter<EquCallOutStateEntity.ResultBean, BaseViewHolder> {
    private boolean mStatus = true;
    private NetworkRequestCallback callback;

    private FragmentManager fragmentManager;

    private Activity activity;
    public GroupEquTransferStateListAdapter(@Nullable List<EquCallOutStateEntity.ResultBean> data, FragmentManager fragmentManager, NetworkRequestCallback callback,Activity activity) {
        super(R.layout.title_equipment_transfer_group,data);
        this.fragmentManager = fragmentManager;
        this.callback = callback;
        this.activity = activity;
    }

    @Override
    protected void convert(BaseViewHolder helper, EquCallOutStateEntity.ResultBean item) {
        helper.setText(R.id.tvLocation,item.getLocation());
        helper.setText(R.id.tvCarrierID,item.getAddress_Id());
        helper.setText(R.id.tvSource,item.getSource());
        helper.setText(R.id.tvEument_state,item.getEqumanet_state_name());

        if("CRE".equals(item.getState())){
            helper.setText(R.id.tvState,"未接工");
        }else{
            helper.setText(R.id.tvState,"已接工");
        }



        if("QC".equals(item.getSource())){
            helper.setText(R.id.tvSource,"QC");
        }else if("TRANSFER".equals(item.getSource())){
            helper.setText(R.id.tvSource,"转工");
        }else{
            helper.setText(R.id.tvSource,"叫修");
        }

        helper.setText(R.id.tvOperation,"转工");
        String roleCheckFlag = item.getRoleCheckFlag();

        helper.getView(R.id.tvOperation).setOnClickListener(view -> {
            if("Y".equals(roleCheckFlag)){
                Context context = helper.itemView.getContext();
                Bundle bundle = new Bundle();
                bundle.putLong("OBJECTRRN",item.getOBJECTRRN());
                Intent intent = new Intent(context, EquipmentTransferCompleteActivity.class);
                intent.putExtras(bundle);
                activity.startActivityForResult(intent,1);
            }else {
                FreeApi_DialogUtils.getConfirmAndCancelDialog(mContext, "是否确认转工?", new FreeUI_CommonCallback() {
                    @Override
                    public void onSuccess() {
                        if (callback != null) {
                            callback.showInputDialog(item.getOBJECTRRN(),item.getState()); // 调用回调方法
                        }
                    }
                }, () -> {}).show(fragmentManager,"CONFIRM_DIALOG");
            }
        });
    }

    public interface NetworkRequestCallback{
        void requestPostNet(long index,String type,String text);
        void showInputDialog(long index,String type);
    }
}
